#ifndef GAME_H
#define GAME_H

#include "Singleton.h"

#include <QDebug>
#include <QList>

class Graphic {
  public:
    virtual ~Graphic(){}
    virtual void Draw()
    {
        qInfo()<<"Graphic" << __FUNCTION__;
    }
    virtual void Load(QString file){};
};

class Image: public Graphic {
  public:
    Image(QString file)
    {
        Load(file);
    }
    virtual ~Image(){}
    virtual void Draw()
    {
        qInfo()<<"Image" << __FUNCTION__;
    }
    virtual const QSize GetSize(){ return _size;}
    virtual void Load(QString file){
        // ...
        _size = QSize(100, 100);    // 来自加载图片的真实大小
    }
protected:
    QSize _size;
};

// virtual proxy
class ImageProxy: public Graphic {
  public:
    ImageProxy(QString file)
    {
        _file = file;
        _size = QSize(0, 0);
        _image = 0;
    }
    virtual ~ImageProxy(){}
    virtual void Draw()
    {
        qInfo()<<"ImageProxy" <<__FUNCTION__;
        GetImage()->Draw();
    }
    virtual const QSize GetSize(){
        if(_size == QSize(0, 0))
            _size = GetImage()->GetSize();
        return _size;
    }

protected:
    Image* GetImage(){
        if(_image == 0)
            _image = new Image(_file);
        return _image;
    }
private:
    Image* _image;
    QSize _size;
    QString _file;
};

#endif // GAME_H
